<?php 
	echo $this->element('reportcss');
	$file_name = $year."年".$month."月入驻企业专利情况统计表";
 	if(empty($report)){?>
<div class="right_side_operate_area">
	<div class="right_side_title left">
		<h2><?php echo $file_name;?></h2>
	</div>
    <?php
    	$url_explode=explode("group=", $_SERVER["QUERY_STRING"]);
    	echo '<div class="right back_btn">';
		echo $html->link("导出报表","/reports/patentsummary/1?year=".$year."&month=".$month."&group=".$url_explode[1]);
		echo '</div>';
	?> 
    <div class="form_sx_drop right">
    	<?php 
 			 $user=$session->read('User');
		 if($user['isadmin']||$user['isvisitor']){
			$grouplist=array_merge(array(""=>"请选择模块"),$grouplist);
	    	echo $form->select('ddlgroup',$grouplist,$group_mod_id, null,null);
			 }
    		$years=$str->getafteryear(0);
    		echo $form->select('ddlyear',$years, $year, null,null);
		    echo $form->select('ddlmonth',$months, $month, null,null);
		?>
	</div>
    <div class="clear"></div>
</div>
<div class="right_side_scollbar">
    <div class="detail_info_panel">
        <div class="items_list">
        <?php }?>
            <?php 
        		if(!empty($report)){
        			echo "<div align='center'><h3>$file_name</h3></div>";
        		}
        	?>
        	<table border='1'>
            	<tr>
                    <th rowspan="2">序号</th>
                    <th rowspan="2">模块</th>
		 			<th rowspan="2">企业名称</th>
		 			<th colspan="4"><?php echo $year;?>年<?php echo $month;?>月申请专利数</th>
		 			<th colspan="4"><?php echo $year;?>年<?php echo $month;?>月授权专利数</th>
		 			<th colspan="4">累计申请专利数</th>
		 			<th colspan="4">累计授权专利数</th>
                </tr>
                <tr>
                	<?php 
                		for($i=0; $i<4; $i++){
	                		echo "<th>实用新型</th><th>发明</th><th>外观</th><th>国外PCT专利</th>";
                		}
                	?>
		 		</tr>
		 		<?php 
		 			$start_time = date('Y-m',strtotime($year.'-'.$month));
		 			$index = 0;
		 			$Constant=classregistry::init('Constant');
		 			foreach($companys as $company){
		 				$index++;
		 				$patents = $company["CompanyPatent"];
		 				$company_name = $company["SearchCompany"]["company_name"];
		 				$groupname = $grouplist[$company["SearchCompany"]["groupid"]];
		 				$appsum_practicle = 0;
		 				$appsum_invent = 0;
		 				$appsum_appearance = 0;
		 				$appsum_PCT = 0;
		 				
		 				$sum_practicle = 0;
		 				$sum_invent = 0;
		 				$sum_appearance = 0;
		 				$sum_PCT = 0;
		 				
		 				$appsum_t_practicle = 0;
		 				$appsum_t_invent = 0;
		 				$appsum_t_appearance = 0;
		 				$appsum_t_PCT = 0;
		 				
		 				$sum_t_practicle = 0;
		 				$sum_t_invent = 0;
		 				$sum_t_appearance = 0;
		 				$sum_t_PCT = 0;
		 				foreach($patents as $patent){
		 					$comp_time = "";
		 					$type = $patenttype[$patent["type_id"]];
		 					if($patent["state"] == '0'){
		 						$comp_time = date('Y-m',strtotime($patent["apply_time"]));
		 						if($type == $Constant->Practice){
		 							if($comp_time !='' && $comp_time <= $start_time){
	 									$appsum_practicle++;
	 								}
	 								if($comp_time !='' && $comp_time == $start_time){
	 									$appsum_t_practicle++;
	 								}
 								}else if($type == $Constant->Invent){
 									if($comp_time !='' && $comp_time <= $start_time){
 										$appsum_invent++;
 									}
	 								if($comp_time !='' && $comp_time == $start_time){
	 									$appsum_t_invent++;
	 								}
 								}else if($type == $Constant->Appearance){
 									if($comp_time !='' && $comp_time <= $start_time){
 										$appsum_appearance++;
 									}
	 								if($comp_time !='' && $comp_time == $start_time){
	 									$appsum_t_appearance++;
	 								}
 								}else if($type == $Constant->PCT){
 								 	if($comp_time !='' && $comp_time <= $start_time){
 										$appsum_PCT++;
 									}
	 								if($comp_time !='' && $comp_time == $start_time){
	 									$appsum_t_PCT++;
	 								}
 								}
		 					}else if($patent["state"] == '2'){
		 						$comp_time = strtotime($patent["authorize_time"]);
		 						if($type == $Constant->Practice){
		 							if($comp_time !='' && $comp_time <= $start_time){
 										$sum_practicle++;
		 							}
	 								if($comp_time !='' && $comp_time == $start_time){
	 									$sum_t_practicle++;
	 								}
 								}else if($type == $Constant->Invent){
 									if($comp_time !='' && $comp_time <= $start_time){
 										$sum_invent++;
 									}
	 								if($comp_time !='' && $comp_time == $start_time){
	 									$sum_t_invent++;
	 								}
 								}else if($type == $Constant->Appearance){
 									if($comp_time !='' && $comp_time <= $start_time){
 										$sum_appearance++;
 									}
	 								if($comp_time !='' && $comp_time == $start_time){
	 									$sum_t_appearance++;
	 								}
 								}else if($type == $Constant->PCT){
 									if($comp_time !='' && $comp_time <= $start_time){
 										$sum_PCT++;
 									}
	 								if($comp_time !='' && $comp_time == $start_time){
	 									$sum_t_PCT++;
	 								}
 								}
		 					}
	 					}
	 					echo "<tr>";
	 					echo "<td align='center' >".$index."</td>";
	 					echo "<td align='center' >".$company_name."</td>";
	 					echo "<td align='center' >".$groupname."</td>";
		 					echo "<td align='center' >".$str->formatquantity($appsum_t_practicle)."</td>";
		 					echo "<td align='center' >".$str->formatquantity($appsum_t_invent)."</td>";
		 					echo "<td align='center' >".$str->formatquantity($appsum_t_appearance)."</td>";
		 					echo "<td align='center' >".$str->formatquantity($appsum_t_PCT)."</td>";
		 					
		 					echo "<td align='center' >".$str->formatquantity($sum_t_practicle)."</td>";
		 					echo "<td align='center' >".$str->formatquantity($sum_t_invent)."</td>";
		 					echo "<td align='center' >".$str->formatquantity($sum_t_appearance)."</td>";
		 					echo "<td align='center' >".$str->formatquantity($sum_t_PCT)."</td>";
		 					
		 					echo "<td align='center' >".$str->formatquantity($appsum_practicle)."</td>";
		 					echo "<td align='center' >".$str->formatquantity($appsum_invent)."</td>";
		 					echo "<td align='center' >".$str->formatquantity($appsum_appearance)."</td>";
		 					echo "<td align='center' >".$str->formatquantity($appsum_PCT)."</td>";
		 					
		 					echo "<td align='center' >".$str->formatquantity($sum_practicle)."</td>";
		 					echo "<td align='center' >".$str->formatquantity($sum_invent)."</td>";
		 					echo "<td align='center' >".$str->formatquantity($sum_appearance)."</td>";
		 					echo "<td align='center' >".$str->formatquantity($sum_PCT)."</td>";
	 					echo "</tr>";
	 				}
		 			
		 		?>
            </table>
<?php if(empty($report)){?>
		</div>
    </div>
</div>

<script>
var webpath=$("#getpath").attr('href');
var urlpath=webpath+"reports/patentsummary/?seach=all";
$(document).ready(function(){
	$("#ddlgroup").change(function(){
		searchproject();
		});
	$("#ddlyear").change(function() {  
		searchproject();
	});
	$("#ddlmonth").change(function(){
		searchproject();
	});
});
function searchproject()
{	
	var group=$("#ddlgroup").val();
	var year = $("#ddlyear").val();
	var month = $("#ddlmonth").val();
	
	if(group==""&& year=="" && month=="" && status=="" && capital==""){
		window.location.href=urlpath;
	}else{
		if(group!=""){
			urlpath+="&group="+group;
			}		
		if(year.trim() != ""){
			urlpath+="&year="+year.trim();
		}
		if(month.trim() != ""){
			urlpath+="&month="+month.trim();
		}
		window.location.href=urlpath;
	}
	return false;
}
</script>
<?php }?>